package com.lollipop.rabbitmq.eight;

import com.lollipop.rabbitmq.util.RabbitMqUtiils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

/**
 * @Author: Lollipop
 * @Date: 2021-10-06 17:19
 * @Description: 成为死信的3个条件：
 * 1.TTL时间到期
 * 2.达到设置的长度
 * 3.消息被拒绝
 */
public class Producer {
    public static final String NORMAL_EXCHANGE = "normal_exchange";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtiils.getChannel();
        // 1.死信条件-死信消息设置TTL时间 单位ms
        /*AMQP.BasicProperties basicProperties = new AMQP.BasicProperties().builder().expiration("10000").build();
        for (int i = 1; i < 11; i++) {
            String message = "message" + i;
            channel.basicPublish(NORMAL_EXCHANGE, "hello", basicProperties, message.getBytes(StandardCharsets.UTF_8));
        }*/

        // 2.死信条件-达到设置的最大队列长度
        for (int i = 1; i < 11; i++) {
            String message = "message" + i;
            channel.basicPublish(NORMAL_EXCHANGE, "hello", null, message.getBytes(StandardCharsets.UTF_8));
        }
    }
}
